package com.suxin.event;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;

import java.util.concurrent.*;

/**
 * @author Tang
 * @classname AbstractApplicationEventMulticaster
 * @description [ 抽象的事件派发者 ]
 * @date 2021/3/17 13:42
 */
public abstract class AbstractApplicationEventMulticaster implements ApplicationEventMulticaster{

    ApplicationContext applicationContext;

    Executor executor;

    public AbstractApplicationEventMulticaster() {
        executor = new ThreadPoolExecutor(Runtime.getRuntime().availableProcessors() + 1,4,10, TimeUnit.MILLISECONDS,
                new ArrayBlockingQueue<>(20), Executors.defaultThreadFactory());
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.applicationContext = applicationContext;
    }

    public Executor getExecutor() {
        return executor;
    }
}